27. Need a Custom ArrayAdapter Exercise

Need a Custom ArrayAdapter Quiz

This exercise will help you practice implementing a custom ArrayAdapter. Complete this before moving on to the next video.


Display List of Numbers (with Miwok and English Translations)

Modify the NumbersActivity

1.Change the ArrayList of Strings called "words" into an ArrayList of Word objects

2.We’re providing you the code that you should add in the onCreate() method of the NumbersActivity. See this link for what the whole file should look like. Make sure your WordAdapter works with this code, otherwise modify your WordAdapter class further.

Create new class WordAdapter

3.Create a new WordAdapter class. Remember to add a new file, go to New > Java Class > and then type in the name of the class WordAdapter.

Create WordAdapter class

Create WordAdapter class

Need CustomArrayAdapter Quiz

4.Modify the auto-generated file from Android Studio. We want the class declaration to specify that the WordAdapter extends or inherits behavior from the ArrayAdapter class.

public class WordAdapter extends ArrayAdapter<Word>  {

5.Use keyboard shortcut Ctl + O to show the available methods to override from the ArrayAdapter class.

Method Override Screenshot

Need Custom ArrayAdapter Quiz

Find getView method and click OK. The getView() method gets generated by default.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
   return super.getView(position, convertView, parent);
}

6.Finish implementing the WordAdapter class by looking at the sample Android Flavors app hosted on Github here. Make sure the code we provided you in NumbersActivity works with your WordAdapter class, otherwise fix your WordAdapter class.

7.Then run the app on your device and make sure the NumbersActivity looks like this screenshot:

NumbersActivity screenshot